package com.sansecy.customview.example;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathMeasure;
import androidx.annotation.Nullable;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class PathMeasure1 extends View {

    private static final String TAG = "PathMeasure1-App";

    public PathMeasure1(Context context) {
        super(context);
    }

    public PathMeasure1(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.translate(50, 50);

        Paint paint = new Paint();
        paint.setColor(Color.RED);
        paint.setStrokeWidth(8);
        paint.setStyle(Paint.Style.STROKE);

        Path path = new Path();
        path.moveTo(0, 0);
        path.lineTo(0, 100);
        path.lineTo(100, 100);
        path.lineTo(100, 0);

        path.addRect(-15, -50, 50, 50, Path.Direction.CW);
        path.addRect(-100, -100, 100, 100, Path.Direction.CW);
        path.addRect(-120, -120, 120, 120, Path.Direction.CW);
        canvas.drawPath(path, paint);

        PathMeasure pathMeasure = new PathMeasure(path, false);
        do {

            float len = pathMeasure.getLength();
            Log.d(TAG, "onDraw: len -- " + len);
        } while (pathMeasure.nextContour());
        canvas.drawPath(path, paint);
    }
}
